package be.one.paq.ui;

import be.one.paq.ui.page.HomePage;
import be.one.paq.ui.page.admin.user.UserPage;
import be.one.paq.ui.page.encodage.EncodagePage;
import be.one.paq.ui.page.reporting.ReportingPage;

import com.vaadin.terminal.ThemeResource;
import com.vaadin.ui.Alignment;
import com.vaadin.ui.Component;
import com.vaadin.ui.ComponentContainer;
import com.vaadin.ui.Embedded;
import com.vaadin.ui.HorizontalLayout;
import com.vaadin.ui.Label;
import com.vaadin.ui.MenuBar;
import com.vaadin.ui.MenuBar.MenuItem;
import com.vaadin.ui.VerticalLayout;

@SuppressWarnings("serial")
public class PAQLevelWindow extends PAQFixedAppLevelWindow {

    @Override
    protected Component createHeader() {
        HorizontalLayout header = new HorizontalLayout();
        header.addStyleName("header");
        header.setHeight("90px");
        header.addComponent(getLogo());
        
        ////// Hello
        Label l = new Label("Hello, I'm a HEADER with a menu.");
        l.setWidth(null);
        header.addComponent(l);
        header.setComponentAlignment(l, Alignment.TOP_RIGHT);

        return header;
    }
    
    private Component getLogo() {
        Embedded logo = new Embedded(null, new ThemeResource("images/logo.png"));
        logo.setStyleName("logo");
        return logo;
    }
    
    @Override
    protected Component createMenu() {
    ///// Menu
        // Design note: this example is bad: 
        // the menu bar should be real <a href="..."> links to each page.
        // Here, on the contrary, when user click, we go back to the server and execute the MenuBar.Command inner class.
        // It internally forwards to the page.
        // But the link does not appears in the browser.
        // Vaadin should propose a MenuBar that also accepts Links as items (instead of Command classes).
        
    	VerticalLayout menu = new VerticalLayout();
    	
        MenuBar menuBar = new MenuBar();
        menuBar.setWidth("100%");
                  
        menuBar.addItem("", new ThemeResource("icons/home.png"), new MenuBar.Command() {
            public void menuSelected(MenuItem selectedItem) {
                getNavigator().navigateTo(HomePage.class);
            }
        });
        
        menuBar.addItem("Encodage", new MenuBar.Command() {
            public void menuSelected(MenuItem selectedItem) {
                getNavigator().navigateTo(EncodagePage.class);
            }
        });
        
        menuBar.addItem("Reporting", new MenuBar.Command() {
            public void menuSelected(MenuItem selectedItem) {
                getNavigator().navigateTo(ReportingPage.class);
            }
        });
        
        final MenuBar.MenuItem admin = menuBar.addItem("Admin", null);
        
        admin.addItem("User", new MenuBar.Command() {
            public void menuSelected(MenuItem selectedItem) {
                getNavigator().navigateTo(UserPage.class);
            }
        });
         
        menu.addComponent(menuBar);
        return menu;
    }

    @Override
    protected Component createFooter() {
        HorizontalLayout footer = new HorizontalLayout();
        footer.addStyleName("footer");
        footer.setHeight("36px");
        
        Label footerLabel = new Label("ONE-PAQ v0.1<br/>Copyright © 2010 - 2011 <a href='http://www.one.be'>ONE</a> - Tous droits réservés", Label.CONTENT_XHTML);
        footerLabel.addStyleName("footer-label");
        footer.addComponent(footerLabel);
                
        return footer; 
    }

    @Override
    protected ComponentContainer createComponents() {
        ComponentContainer result = super.createComponents();
        return result;
    }

}
